const common = require('./webpack.common')
const { merge } = require('webpack-merge')
const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

//合并配置 覆盖前一个对象的同名属性，但是plugins数组要在原有的基础上添加插件,需要webpack-merge可以实现，而js的Object.
//yarn webpack --config webpack.prod.js
module.exports = merge(common, {
    mode: 'development',
    devtool: 'cheap-module-eval-source-map',
    devServer: {
        // 设置webpack-dev-server 可以访问的文件
        contentBase: [path.resolve(__dirname, 'dist'), path.resolve(__dirname, 'public')],
        hotOnly: true
    },
    plugins: [
        new webpack.DefinePlugin({
            BASE_URL: JSON.stringify('')
        }),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
        new webpack.NoEmitOnErrorsPlugin(),
        new HtmlWebpackPlugin({
            template: './public/index.html',
            filename: 'index.html',
            title: 'Vue App Base',
            inject: true,
        }),
    ]
})